using B.S.NewMedical.Api.Read.Application.Command.ContentManagement.Carousel;
using B.S.NewMedical.Api.Read.DTOS.Carousel;
using B.S.NewMedical.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace B.S.NewMedical.Api.Read.Controllers.ContentManagement.Carousel
{
    /// <summary>
    /// 轮播图查询控制器
    /// </summary>
    [Route("api/ContentManagement/[controller]")]
    [ApiController]
    public class CarouselController : ControllerBase
    {
        private readonly IMediator _mediator;

        public CarouselController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 获取轮播图列表（支持分页、标题模糊查询、时间区间查询）
        /// </summary>
        /// <param name="queryDto">查询条件</param>
        /// <returns>轮播图分页列表</returns>
        [HttpGet]
        public async Task<ApiPageing<List<CarouselDto>>> GetCarousels([FromQuery] CarouselQueryDto queryDto)
        {
            return await _mediator.Send(new GetCarouselsCommand(queryDto));
        }

        /// <summary>
        /// 根据ID获取轮播图详情
        /// </summary>
        /// <param name="id">轮播图ID</param>
        /// <returns>轮播图详情</returns>
        [HttpGet("{id}")]
        public async Task<ApiResult<CarouselDto>> GetCarouselById(int id)
        {
            return await _mediator.Send(new GetCarouselByIdCommand(id));
        }

        /// <summary>
        /// 获取启用的轮播图列表（用于前端显示）
        /// </summary>
        /// <returns>启用的轮播图列表</returns>
        [HttpGet("enabled")]
        public async Task<ApiPageing<List<CarouselDto>>> GetEnabledCarousels()
        {
            var queryDto = new CarouselQueryDto
            {
                Status = true,
                PageSize = 50 // 获取更多数据用于轮播显示
            };
            return await _mediator.Send(new GetCarouselsCommand(queryDto));
        }
    }
}